#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
//        map<int, int> map = new HashMap<>();
        unordered_map<int, int> m;
        vector<int> result;
        for(int i=0; i<nums.size(); i++){
            m[nums[i]] = i;
        }
        for(int i=0; i<nums.size(); i++){
            int complement = target - nums[i];
            if(m.count(complement) && m.find(complement) != m.end()){
                if (m.find(complement)->second != i) {
                    result.push_back(i);
                    result.push_back(nums[i]);
                }
            }
        }
        return result;
    }
};
int main() {
    int n[] = {1, 2, 3, 4, 5};
    int target = 9;
    vector<int> a(n, n+5);
    Solution test1;
    vector<int> b = test1.twoSum(a, target);
    int i=0;
    while(!b.empty()){
        cout<< b.at(i) << endl;
        i++;
    }
    return 0;
}
